﻿CREATE PROCEDURE [dbo].[s_Technician_Tracker_InHands]
	@TechnicianID int,
	@TrackerIDs varchar(4000)
AS

IF @TechnicianID = -1000000 BEGIN -- Undo (t_MenuEvents)
	INSERT INTO t_Technician_Tracker(TechnicianID, TrackerID)
	SELECT   TechnicianID_Last,@TrackerIDs FROM dbo.hist_Tracker__Last(@TrackerIDs)
	RETURN
END

BEGIN TRAN

INSERT INTO t_Technician_Tracker(TechnicianID, TrackerID)
SELECT @TechnicianID, Element FROM Split(@TrackerIDs,',')

IF @@ERROR <> 0 BEGIN	IF @@TRANCOUNT > 0 ROLLBACK TRAN RETURN END

/**/DECLARE @CI int EXEC @CI = sp__Context_WorkFlow_System 1
UPDATE t_Tracker SET StatusID = dbo.MenuIDByProcID(@@PROCID)
WHERE ID IN (SELECT Element FROM Split(@TrackerIDs,','))
/**/IF @@ERROR = 0 COMMIT TRAN
/**/EXEC sp__Context @CI











